package com.xbj.dao;

import com.xbj.model.User;

import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.io.IOException;
import java.io.InputStream;

/**
 * Created by JzzZ
 * Date: 2018\7\1 0001
 * Time: 16:58
 * Project: News2.0
 * File description: UserDao接口实现类
 */
@Repository
public class UserDaoImpl implements UserDao {
    @Autowired
    public SqlSessionTemplate sessionTemplate;

    @Override
    public User selectUserById() {
//        这里要使用命名空间 + SQL id才可以
//        User user = sqlSession.selectOne("com.xbj.model.UserMapper.selectByPrimaryKey");
        User user = sessionTemplate.selectOne("com.xbj.model.UserMapper.selectByPrimaryKey");
        return user;

    }

    @Override
    public User selectByUsernameAndPassword(User user) {
        User u = sessionTemplate.selectOne("com.xbj.model.UserMapper.selectByUsernameAndPassword", user);
        return u;
    }

    @Override
    public void updateUser(User user) {
//        sqlSession.update("com.xbj.model.UserMapper.updateByPrimaryKeySelective", user);
        sessionTemplate.update("com.xbj.model.UserMapper.updateByPrimaryKeySelective", user);
    }
}
